import { ILoadMapTypeAll } from '@/common';
import { getSelectDataCommon, getSelectDataMapList, getTenantID } from '@/utils';
import { MaterialAndAssetControllerAPI } from '../common/type';
import { useEffect, useState } from 'react';
import { getStorageTreeService } from '../../Assetmanagement/AssetAllot/services';
/**
 * @param {Object} loadMdicMapList 数据字典
 * @param {Object} areaListData 地区字典
 * */
const ManageSearchColumns = (loadMdicMapList: Record<string, any>, queryTypeObj: Record<string, any>): MaterialAndAssetControllerAPI.IHeaderSearchType => {
  /** 物资分类数据字典 */
  // const materialTypeMapList = loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.MATERIAL_TYPE}`];
  const materialTypeMapList = getSelectDataMapList(loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.MATERIAL_TYPE}`], 'name', 'id', true);

  /** 物资状态数据字典 */
  const materialState = getSelectDataCommon(loadMdicMapList?.[`${getTenantID()}${ILoadMapTypeAll.MATERIEL_STATUS}`], 'name', 'id');
  const materialStates = materialState?.filter((v) => v.name == '已入库' || v.name == '待入库');

  // 仓库树数据
  const [storageList, setStorageList] = useState<any>([]);

  // 获取仓库树回调
  const updataGetStorage = (res: any) => {
    if (res && res?.msgFlag) {
      setStorageList(res?.obj);
    }
  };

  // 获取仓库树
  const { getStorageLoading, getStorageRun } = getStorageTreeService(updataGetStorage, queryTypeObj?.curRes);

  useEffect(() => {
    getStorageRun();
  }, []);

  const MaterialType = [
    {
      name: '材料',
      value: '0',
    },
    {
      name: '资产',
      value: '1',
    },
  ];

  const searchColumns: MaterialAndAssetControllerAPI.ISearchList = [
    {
      name: 'assetName',
      placeholder: '物资名称',
      label: '物资名称',
      componentType: 'Input',
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'type',
      placeholder: '物资种类',
      label: '物资种类',
      componentType: 'Select',
      dataSource: MaterialType,
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
    },
    {
      name: 'assetClass',
      placeholder: '物资分类',
      label: '物资分类',
      componentType: 'TreeSelect',
      dataSource: materialTypeMapList,
      allowClear: true,
      showSearch: true,
      treeNodeFilterProp: 'name',
      md: 6,
      sm: 24,
      whetherSenior: false,
      treeID: 'id',
      treeName: 'name',
      treeChildren: 'children',
    },
    {
      name: 'assetState',
      placeholder: '物资状态',
      label: '物资状态',
      componentType: 'Select',
      dataSource: materialStates,
      allowClear: true,
      md: 6,
      sm: 24,
      whetherSenior: false,
    },
    // {
    //   name: 'assetStoreId',
    //   placeholder: '所属仓库',
    //   label: '所属仓库',
    //   componentType: 'TreeSelect',
    //   dataSource: storageList,
    //   allowClear: true,
    //   md: 6,
    //   sm: 36,
    //   whetherSenior: false,
    //   treeID: 'id',
    //   treeName: 'storeName',
    //   treeChildren: 'children',
    // },
    /**===============================高级搜素================================*/
  ];

  return searchColumns;
};

export { ManageSearchColumns };
